<template>
    <div class="wrapper">
        <van-row type="flex" justify="center">
            <van-image
                    round
                    width="20vw"
                    height="20vw"
                    :src="userInfo.avatar"
                    fit="cover"
            />
        </van-row>
        <van-row type="flex" justify="center">
            <p style="margin: 10px">欢迎您,{{ userInfo.uname }}</p>
        </van-row>
        <!--信息内容-->
        <van-cell-group inset>
            <van-cell title="岗位名称" :value="myjob.jobname"/>
            <van-cell title="入职日期" :value="myjob.indate|dateFmt" label="入职时间"/>
            <van-cell title="转正日期" :value="myjob.zzdate|dateFmt" label="计划转正日期"/>
            <van-cell title="基础工资" :value="myjob.jcgz" label="基础工资"/>
            <van-cell title="医疗保险" value="0" label="入职满一年购买"/>
            <van-cell title="养老保险" value="0" label="入职满一年购买"/>
            <van-cell title="失业保险" value="0" label="入职满一年购买"/>
            <van-cell title="工伤保险" value="0" label="入职满一年购买"/>
            <van-cell title="住房公积金" value="0" label="入职满一年购买"/>
        </van-cell-group>

        <van-row type="flex" justify="center">
            <van-button @click="handleLogOut" style="margin: 10px"
            >退出登录
            </van-button
            >
        </van-row>
    </div>
</template>

<script>
    import $store from "@/store/index";
    import $router from "@/router/index";
    import $api from "@/api/index";
    import {getStore, setStore} from "../../utils";

    export default {
        data() {
            return{
                myjob:[], //我的工作信息
            }
        },
        created(){
          this.getUserJob()
        },
        computed: {
            userInfo() {
                return $store.getters["user/info"] || {};
            },
        },
        methods: {
            handleLogOut() {
                $store.dispatch("user/logout");
                $router.replace("/login");
            },
            //用户信息
            async getUserJob(){
                //存入本地sessionStorage，减少请求次数
                const rout = window.sessionStorage.getItem("empujob")
                if(rout=='' || rout==null){
                    const result =await $api.userjob.getjb();
                    // setStore("empujob",result.data)
                    window.sessionStorage.setItem("empujob",JSON.stringify(result.data))
                    this.myjob = result.data
                }else{
                    this.myjob = JSON.parse(rout)
                }
            }
        },
        //时间格式过滤
        filters: {
            dateFmt: function (value) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? "0" + MM : MM;
                let d = date.getDate();
                d = d < 10 ? "0" + d : d;
                let h = date.getHours();
                h = h < 10 ? "0" + h : h;
                let m = date.getMinutes();
                m = m < 10 ? "0" + m : m;
                let s = date.getSeconds();
                s = s < 10 ? "0" + s : s;
                return y + "-" + MM + "-" + d + " ";
            }
        }
    };
</script>

<style scoped lang="scss">
    .wrapper {
        padding-top: 50px;
    }
</style>
